from pymongo import MongoClient


class MongoBase:
    def __init__(self, collection, config):
        self._config = config
        self.collection = collection
        self.OpenDB()

    def OpenDB(self):
        # user='******'
        # passwd='******'
        # host='******'
        # port='******'
        # auth_db='******'
        # uri = "mongodb://"+user+":"+passwd+"@"+host+":"+port+"/"+auth_db+"?authMechanism=SCRAM-SHA-1"
        self.con = MongoClient(self._config.host, self._config.port)
        self.db = self.con[self._config.database]
        self.collection = self.db[self.collection]

    def closeDB(self):
        self.con.close()
